/**
 * 
 */
package com.nassir.excel.cellwriter;

import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;

import com.nassir.excel.model.Cell;

/**
 * @author zhangqiulong
 *
 */
public class DateCellWriter implements ICellWriter<Date> {

	public boolean accept(String type) {
		return CELL_TYPE_DATE.equals(type);
	}

	public void write(HSSFCell cell, Cell head, Date data) {
	   if(data != null) {
	       cell.setCellValue(data);
	       HSSFCellStyle cellStyle = cell.getSheet().getWorkbook().createCellStyle(); 
	       cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(head.getFormat())); 
	       cell.setCellStyle(cellStyle);
	   }else {
	       cell.setCellValue("");
	   }
	}

}
